package com.starfleet.galleryofdingao

import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.content.ContextCompat.startActivity
import com.starfleet.galleryofdingao.ui.theme.GalleryOfDingsExTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            GalleryOfDingsExTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    val intent = Intent(this,exActivity::class.java) //enables the button to jump  to another page.
                    DingAoContent(intent,this)
                }
            }
        }
    }
}

@Composable
fun DingAoContent(intent : Intent,context : MainActivity){
    var imgNum by remember { mutableIntStateOf(1) }
    val DingAoImages = when(imgNum){
        1 -> R.drawable.furious_ding_ao
        2 -> R.drawable.despise_ding_ao
        3 -> R.drawable.eating_0
        4 -> R.drawable.eating_1
        5 -> R.drawable.eating_2
        6 -> R.drawable.eating_3
        else -> R.drawable.twisted_ding_ao
    }
    Column(
        verticalArrangement = Arrangement.Center,
        modifier = Modifier.verticalScroll(rememberScrollState()),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        Image(
            painter = painterResource(id = DingAoImages),
            contentDescription = "A photo of Ding Ao",
            modifier = Modifier
                .requiredSize(width = 200.dp, height = 200.dp)
                .align(alignment = Alignment.CenterHorizontally).border(5.dp, Color.Green)
        )
        Text(text = stringResource(R.string.my_avatar_rights),
            modifier = Modifier.padding(start = 10.dp, end = 10.dp),
            fontSize = 10.sp
            )
        Button(onClick = {
            imgNum = if(imgNum < 7) imgNum+1 else 1
        }
        ) {
            Text(text = stringResource(R.string.Avatar_Rotate_Button_Description))
        }
        Text(
            text = stringResource(R.string.ding_ao_name),
            textAlign = TextAlign.Center,
            fontSize = 80.sp,
            modifier = Modifier
                .padding(bottom = 4.dp)
                .align(alignment = Alignment.CenterHorizontally)
            )
        Text(text = stringResource(R.string.Self_description),
            modifier = Modifier.padding(start = 10.dp, end = 10.dp)
            )


        Button(onClick = { startActivity(context,intent,null) }) {
            Text(text = stringResource(R.string.Activity_jump_button_description))
        }
    }
}

/*
    Ain't be needing preview.
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    GalleryOfDingsExTheme {
        //Greeting("Ding Ao")
    }
}
*/
